package compraventa.servlet;

import compraventa.negocio.GestionCategoria;

/**
 * Servlet implementation class for Servlet: RolInsertarServlet
 * 
 */
@WebServlet("/CategoriaInsertarServlet")
public class CategoriaInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public CategoriaInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String nom = request.getParameter("nombre");
		String des = request.getParameter("descripcion");
		int cat = 0;	//request.getParameter("categoria_idcategoria");
		
		GestionCategoria negocio = new GestionCategoria();
		try {
			negocio.insertar(nom, des, cat);
			response.sendRedirect(request.getContextPath()	+ "/scv_principal.jsp");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}
}